<?php

/**
 * IndexController - The default controller class
 * 
 * @author
 * @version 
 */

#require_once 'Zend/Controller/Action.php';

class IndexController extends Zend_Controller_Action 
{
	/**
	 * The default action - show the home page
	 */

	public function init()
	{
		#$this->initView();
		#$messages = $this->_helper->getHelper('FlashMessenger')->getMessages();
   		#$this->view->assign('flashmessenger', $messages[0]);  
		#$this->view->baseUrl = $this->_request->getBaseUrl();
		#$this->view->baseUrl =  $this->getRequest()->getBaseUrl();
		#$this->getHelper('BaseUrl')->BaseUrl();
		#$this->view->identityuser= Zend_Auth::getInstance()->getIdentity();
		#$this->routen();
		$uri = $this->_request->getPathInfo();
		$activeNav = $this->view->navigation()->findByUri($uri);
		$activeNav->active = true;
		$this->sms();
	}	
	
    public function deniedAction()
    {
   		$this->view->title="Zugriff Verweigerung"; 	
	}
	
	public function aboutusAction()
    {
			
	}
	
	public function sitemapAction()
    {
    	# News
		$db= Zend_Registry::get('db');
    	$select= $db->SELECT()->FROM('news')->order('datum DESC');
		#$page= $this->_request->getParam('page');
		$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
		$paginator->setItemCountPerPage(4);
		#$paginator->setCurrentPageNumber($page);
		$this->view->paginator=$paginator;			
	}
	
	public function philosophieAction()
    {
			
	}
	
	public function referencesAction()
    {
			
	}
	
	public function recruitingAction()
    {
				
	}
	
	public function managedAction()
    {
				
	}
	
	public function onsiteAction()
    {
				
	}
    
	public function impressumAction()
	{
		
	}
	
	public function testAction()
	{
		$this->_helper->layout()->disableLayout();
	}
	
	public function agbAction()
	{
		
	}
	
	public function bewerbenAction()
	{
		
	}
	
	public function aktuellestellenangeboteAction()
	{
		
	}
	
	public function smsAction()
	{
		
	}
	
	public function faqsAction()
	{
		# News
		$db= Zend_Registry::get('db');
    	$select= $db->SELECT()->FROM('news')->order('datum DESC');
		#$page= $this->_request->getParam('page');
		$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
		$paginator->setItemCountPerPage(4);
		#$paginator->setCurrentPageNumber($page);
		$this->view->paginator=$paginator;
		
	}
	
	public function zehngruendeAction()
	{
		# News
		$db= Zend_Registry::get('db');
    	$select= $db->SELECT()->FROM('news')->order('datum DESC');
		#$page= $this->_request->getParam('page');
		$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
		$paginator->setItemCountPerPage(4);
		#$paginator->setCurrentPageNumber($page);
		$this->view->paginator=$paginator;
		
	}
	
	
	public function datenschutzAction()
	{
		
	}
	
	public function servicesAction()
	{
		
	}
	
	public function kontaktAction()
	{
		$form = new Somi_Form_Kontakt();
		$this->view->form=$form;
		if($this->_request->isPost())
		{
			$formData=$this->_request->getPost();
			if($form->isValid($this->_request->getPost()))
			{
				$empfänger= 'info@somi.de';
				$mail = new Zend_Mail('UTF-8');
				$mail->setSubject('Anfrage von Kontakt');
				
				$mail->setFrom('Kontakt','SOMI Solutions');
				$mail->addTo($empfänger);
				while(list($Formularfeld, $Wert) = each($_REQUEST))
        			{
						$text .="\n".$Formularfeld.": ".$Wert;
        			}
        						
				$mail->setBodyText('Jemanden hat sich über www.SOMI.de kontaktiert. '.$text);
				
				if($mail->send()){
				echo	'<div align="center" id="flashmessenger" style="position:absolute;top:215px;left:35%;background:#fff;color:red;font-size:15px;height:20px;">
						Nachricht wurde verschickt....
						</div>';
						$form->reset();
				}else{					
					$this->view->flashMessenger = 'Nachricht könnte nicht verschickt werden....';
				}
				
			}else{
				$form->populate($formData);
			}
		}			
	}
	
	public function facebookAction()
	{
		# News
		$db= Zend_Registry::get('db');
    	$select= $db->SELECT()->FROM('news')->order('datum DESC');
		#$page= $this->_request->getParam('page');
		$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
		$paginator->setItemCountPerPage(4);
		#$paginator->setCurrentPageNumber($page);
		$this->view->paginator=$paginator;
	}

	public function carriereAction()
	{
		$jobi =new Somi_Models_Jobi();
		$form = new Somi_Form_Jobi();
		$form->removeElement('phone1');
		$form->removeElement('phone2');
		$form->removeElement('stadt');
		$form->removeElement('taetigkeit');
		$form->removeElement('qualifikation');
		$form->removeElement('kommentar');
		$form->removeElement('status');
		$this->view->form=$form;
		if($this->_request->isPost())
    	{
    		$formData=$this->_request->getPost();
   
    		if ($form->isValid($formData))
    		{ 
    			
    			$daten=array(
    			'vorname' =>$form->getValue('vorname'),
    			'nachname'=>$form->getValue('nachname'),
    			'email'=>$form->getValue('email'),
    			'created' => Zend_Date::now('de_DE'),
    			);
    			$jobi->insert($daten);
    			$form->reset();
    			$this->view->message = "Erfolgreich gesendet.";
    			//$this->_helper->flashMessenger('Firmendaten wurde erfolgreich erstellt');
    			//$this->_redirect(Somi_Plugin_Predispatch::redirectBackUrl());
    		}else{
    			#echo '<script type="text/javascript">dijit.byId("jobi").show();</script>';
    			$form->populate($formData);
    			echo '<script type="text/javascript">function setupMove() {dijit.byId("jobi").show()}dojo.addOnLoad(setupMove);</script>';    			
    		}
    	}
	}
	
	public function downloadsAction()
	{
		# News
		$db= Zend_Registry::get('db');
    	$select= $db->SELECT()->FROM('news')->order('datum DESC');
		#$page= $this->_request->getParam('page');
		$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
		$paginator->setItemCountPerPage(4);
		#$paginator->setCurrentPageNumber($page);
		$this->view->paginator=$paginator;
	}

	public function twitterAction()
	{
		# News
		$db= Zend_Registry::get('db');
    	$select= $db->SELECT()->FROM('news')->order('datum DESC');
		#$page= $this->_request->getParam('page');
		$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
		$paginator->setItemCountPerPage(4);
		#$paginator->setCurrentPageNumber($page);
		$this->view->paginator=$paginator;
	}
	
	public function newsAction() 
    {        
        # News
		$db= Zend_Registry::get('db');
    	$select= $db->SELECT()->FROM('news')->order('datum DESC');
		#$page= $this->_request->getParam('page');
		$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
		$paginator->setItemCountPerPage(4);
		#$paginator->setCurrentPageNumber($page);
		$this->view->paginator=$paginator;  	
    }
	
    public function indexAction() 
    {        
        #Zend_Layout::startMvc(array('layoutPath' => APPLICATION_PATH.'/default/layouts','layout' => 'mainindex'));
    	#$this->view->title="Inventarisierung";
        // Die FlashMesseger soll hier wieder ausgeben 
        #$this->view->baseUrl = $this->_request->getBaseUrl();
        # News
		$db= Zend_Registry::get('db');
    	$select= $db->SELECT()->FROM('news')->order('datum DESC');
		#$page= $this->_request->getParam('page');
		$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
		$paginator->setItemCountPerPage(4);
		#$paginator->setCurrentPageNumber($page);
		$this->view->paginator=$paginator;  	
    }
    
    public function obewerbenAction()
    {
    	#$this->view->title="Inventarisierung";
		#$this->_helper->layout()->disableLayout();
		Zend_Layout::startMvc(array('layoutPath' => APPLICATION_PATH.'/default/layouts','layout' => 'main2'));
		  	
    	$form = new Somi_Form_BewerbenForm();    
        $this->view->form = $form; 
        if($this->_request->isPost())
		{
			$formData=$this->_request->getPost();
			if($form->isValid($this->_request->getPost()))
			{
				// Daten für SMTP-Authentifizierung definieren
				#$smtpAuthentication=array(
				#'ssl' => 'tls',
				#'port' => '587',				
				#'auth'=> 'Login',
				#'username' => 'admin@somi.de',
				#'password' => 'jamanaller',
				#);
				$i =0;
				$file=@fopen($_FILES['file']['tmp_name'],"r");
				if($file){
				$uploaddatei = fread(fopen($_FILES['file']['tmp_name'],"r"),$_FILES['file']['size']);
				}
				$empfänger= $form->getValue('email');
				$nachname = $form->getValue('nachname');
				$titel= $form->getValue('titel');
				$anrede= $form->getValue('anrede');
				//Versand per SmTP
				#$tr = New Zend_Mail_Transport_Smtp('smtp.googlemail.com',$smtpAuthentication);
				#Zend_Mail::setDefaultTransport($tr);
				
				do{
				$i++;				
				if($i==1){
				// Mail im UTF-8- Format
				$mail = new Zend_Mail('UTF-8');				
				$mail->setSubject('SOMI Solutions GmbH - Bewerbung');
				$mail->setBodyHtml('Sehr geehrte/r '.$anrede.' '. ucfirst($titel).' '.ucfirst($nachname).',<br><br>vielen Dank f&uuml;r Ihre Bewerbung und das Interesse an der SOMI Solutions GmbH. Ihre Daten werden vom System aufgenommen und von unseren Service-Mitarbeiter zeitnah bearbeitet.
				<br><br><br>[Dies ist eine automatisch generierte Nachricht, bitte antworten Sie nicht an diesen Absender.]
				<br><br>Hilfe & Kontakt:
				<br>
				================
				<br>
				Haben Sie weitere Fragen zu unseren Leistungen? 
				<br>
				Gerne sind unsere Mitarbeiter auch telefonisch für Sie da.
				<br>
				Sie erreichen uns montags - freitags von 09:00 bis 17:00 Uhr
				<br><br>
				<p class="MsoNormal" style="line-height: normal;"><a name="_MailAutoSig"><span style="font-size: 10pt;" lang="EN-US">_______________________________________</span></a><span style=""></span><span style="font-size: 12pt;" lang="EN-US"><br>
				<b><span style="color: rgb(0, 0, 127);">Webmaster - SOMI Solutions</span></b><o:p></o:p></span></p>	
				<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><b><span style="font-size: 9pt;" lang="EN-US">SOMI Solutions
				 GmbH</span></b><span style="font-size: 12pt;" lang="EN-US"><o:p></o:p></span></p>
				<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;" lang="EN-US">Kennedyallee 
				93 <b>|</b> 60596 Frankfurt am Main <b>|</b>
				Germany<br>
				Tel +49 69 578 041 80 <b>|</b> Fax +49 577 067 19&nbsp; <b>|</b> </span><span style="font-size: 12pt;" lang="EN-US"><br>
				</span><a href="mailto:support@somi.de" target="_blank"><span style="font-size: 9pt;" lang="EN-US">support@somi.de</span></a><span style="font-size: 12pt;"> </span><b><span style="font-size: 9pt; font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; color: gray;" lang="EN-US">| </span></b><a href="mailto:info@somi.de" target="_blank"><span style="font-size: 9pt;" lang="EN-US">info@somi.de</span></a><span style="font-size: 9pt;"> </span><b><span style="font-size: 9pt;" lang="EN-US">|</span></b><span style="font-size: 9pt;" lang="EN-US"> </span><a href="http://www.somi.de/" target="_blank"><span style="font-size: 9pt; font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; color: navy;" lang="EN-US">www.somi.de</span></a><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;" lang="EN-US"><o:p></o:p></span></p>
				<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;"><br>
				HRB 88152, Amtsgericht Frankfurt am Main<br>
				</span><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;"><o:p></o:p></span></p>
				<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 12pt;"><o:p>&nbsp;</o:p></span></p>
				<p class="MsoNormal"><span style="font-size: 9pt; line-height: 115%; font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; color: gray;">Diese E-Mail enthält vertrauliche und/oder rechtlich
				geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder
				 diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den 
				Absender und vernichten Sie diese Mail. <br>
				Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind 
				nicht gestattet. Weitergabe sowie Vervielfältigung dieser vertraulichen 
				Unterlage(n),
				Verwertung und Mitteilung ihres Inhaltes ist nicht ohne unsere vorherige
				<br>schriftliche Genehmigung gestattet. Zuwiderhandlungen verpflichten zu
				Schadenersatz. Alle Rechte für den Fall der Patenterteilung oder
				Gebrauchsmuster-Eintragung vorbehalten.</span></p> ');
				$mail->setFrom('bewerbung@somi.de','SOMI Solutions GmbH');
				$mail->addTo($empfänger);	
				$mail->addHeader('X-MailGenerator','SOMI Solutions GmbH');
				$mail->addHeader('X-greetingsTo','ADMIN');
				$mail->send();
				}
				
				if($i==2){
				$mail = new Zend_Mail('UTF-8');
				$mail->setSubject('Anfrage von Personal');
				
				$mail->setFrom('admin','SOMI Solutions');
				$mail->addTo($empfänger);
				while(list($Formularfeld, $Wert) = each($_REQUEST))
        			{
						$text .="\n".$Formularfeld.": ".$Wert;
        			}
        						
				$mail->setBodyText('Jemanden hat sich über Personal.SOMI.de beworben. '.$text);
				if($file)
        		{	
				//Anhang				
				$at= $mail->createAttachment($uploaddatei);
				$at->type	= $_FILES['file']['type'];
				$at->filename = $_FILES['file']['name'];
        		}
				$mail->send();
				
				}				
				
				$empfänger= 'bewerbung@somi.de';
				}while($i < 2);
				echo '<script type="text/javascript"> window.close()</script> ';			
			}
			else{
				$form->populate($formData);
			}
		}


    }
    
    public function dankeAction(){
    	Zend_Layout::startMvc(array('layoutPath' => APPLICATION_PATH.'/default/layouts','layout' => 'main2'));
    }
    
    public function preDispatch()
    {

    }
    
    
	public function routen(){			
		$auth =Zend_Auth::getInstance();
    	if(!$auth->hasIdentity()){
    		// Erzeuge eine FlashMessanger
    		#$this->_helper->flashMessenger('Sie sind nicht eingeloggt,Bitte loggen Sie sich ein.');
    		$this->_redirect('auth/login');
    	}else{
	    	if($auth->getIdentity()->role=='Inaktiv'){
	    	$this->_redirect('/inaktiv');
	    	}
			elseif($auth->getIdentity()->role=='Kunden'){
	    		$this->_redirect('/kunden');
			}
			elseif($auth->getIdentity()->role=='Admin'){
	    		$this->_redirect('/admin');
			}
			
			
		}
	}
	
	
	public function sms(){
		// Formular laden
    	$form=new Somi_Form_Login();
    	$form->setAction('http://sms.somi.de/auth/login');
    	$form->setAttrib('target','blank');
		$form->getElement('username')->setAttrib('style',array('width:180px;'));
		$form->getElement('password')->setAttrib('style',array('width:180px;'));
		$this->view->login=$form;
	}
    
}
